//
//  NGovIndustryBaobiaoViewController.m
//  nncloud
//
//  Created by macfai on 2018/12/20.
//  Copyright © 2018 macfai. All rights reserved.
//

#import "NGovIndustryBaobiaoViewController.h"
#import "NFeedbackCell.h"
#import "NTianBaoDetailViewController.h"
#import "NIndustyBaobiaoModel.h"
@interface NGovIndustryBaobiaoViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong)UITableView *tableView;

@property (nonatomic,strong)NSMutableArray *dataArray;

@end

@implementation NGovIndustryBaobiaoViewController

#define cellIdentifier  @"feedbackid"
#define HeaderHight  290
#define PageSize 20

-(UITableView *)tableView{
    
    if (!_tableView) {
        
        WeakStament(ws);
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0 , 0, ScreenWidth , ScreenHeight - 64) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = 80.f;
        //        _tableView.separatorColor = [UIColor clearColor];
        _tableView.backgroundColor = kBackgroundColor;
        [_tableView registerNib:[UINib nibWithNibName:@"NFeedbackCell" bundle:nil] forCellReuseIdentifier:cellIdentifier];
        //        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        //            [ws loadData];
        //        }];
        //        _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        //            [ws loadMoreData];
        //        }];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.tableFooterView = [UIView new];
        
    }
    return _tableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kWhiteColor;
    if ([_userType isEqualToString:@"2"]) {
        //政府
        [self.navigationItem setItemWithTitle:@"工业报表" textColor:kNavigationTitleColor fontSize:18 itemType:center];
    }else{
        //企业
        [self.navigationItem setItemWithTitle:@"我的工业报表" textColor:kNavigationTitleColor fontSize:18 itemType:center];
    }
    
    self.dataArray = [NSMutableArray array];
    [self.view addSubview:self.tableView];
    [self loadData];
    // Do any additional setup after loading the view from its nib.
}



- (void)loadData{

    NSDictionary *dic;
    NSString *url;
    if ([_userType isEqualToString:@"1"]) {
        ///企业端
        dic = @{@"userId":[NUserModel shareInstance].userInfoId?[NUserModel shareInstance].userInfoId:@""};
        url = kIndustryReportListUrl;
        
    }else{
        ///政府
        dic = @{};
        url = kGovIndustryReportUrl;
    }
    
    [[NNRCNetRequest manager]getWithUrl:url params:dic success:^(id result) {
        YYLog(@"%@",result);
        WeakStament(ws);
        if ([[result objectForKey:@"code"] integerValue] == 0) {
            
            NSArray *arr = result[@"page"][@"records"];
            YYLog(@"%@",arr);
            if (arr.count>0) {
                for (NSDictionary *dict in arr) {
                    NIndustyBaobiaoModel *model = [NIndustyBaobiaoModel mj_objectWithKeyValues:dict];
                    [ws.dataArray addObject:model];
                }
            }else{
                [AFToast showText:@"没有查到相关数据"];
                return ;
            }
            
            [ws.tableView reloadData];
            
        }else{
            [AFToast showText:result[@"msg"]];
        }
        
    } failure:^(id failure) {
        
    }];
}

#pragma mark - delegate datasource

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NIndustyBaobiaoModel *model = self.dataArray[indexPath.row];
    NTianBaoDetailViewController *detail = [NTianBaoDetailViewController new];
    detail.hidesBottomBarWhenPushed = YES;
    if (model.industryId) {
        detail.baobiaoId = model.industryId;
    }
    detail.atitle = @"工业报表详情";
    
    [self.navigationController pushViewController:detail animated:YES];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    NFeedbackCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    NIndustyBaobiaoModel *model = self.dataArray[indexPath.row];
    cell.industryBaobiaoModel = model;
    cell.tipLabel.hidden = YES;
    //    if (self.dataArray.count>indexPath.row) {
    //
    //    }
    return cell;
}

@end
